package org.ricks.net.action.context.session;

import org.ricks.net.action.utils.RpcException;
import org.ricks.net.http.server.WebSocketResponse;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

// WebSocket 会话适配器
public class WebSocketSessionAdapter extends Session {

    private final WebSocketResponse response;

    public WebSocketSessionAdapter(WebSocketResponse response) {
        this.response = response;
    }

    @Override
    public void writeBinary(byte[] data) {
        response.sendBinaryMessage(data);
        response.flush();
    }

    @Override
    public void writeText(String text) {
        response.sendTextMessage(text);
        response.flush();
    }

    @Override
    public void close() {
        response.close();
    }

    @Override
    public <R> CompletableFuture<R> invoke(short cmd, Object body, Class<R> resultType) {
        throw new RpcException("websocket 不支持请求响应模式 ！");
    }

    @Override
    public <R> CompletableFuture<R> invoke(short cmd, Object body, Class<R> resultType, long timeout, TimeUnit unit) {
        throw new RpcException("websocket 不支持请求响应模式 ！");
    }
}
